package com.qigao.mall.web.controller.app.user;

import com.qigao.mall.api.NoticeService;
import com.qigao.mall.commons.dto.NoticeResultDto;
import com.qigao.mall.commons.enums.Result;
import com.qigao.mall.commons.enums.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author luiz
 * @Title: com.qigao.mall.web.controller.app
 * @ProjectName three-mall
 * @date 2019-11-2019/11/5 16:17
 * @Description:
 */
@RestController
@RequestMapping("/app/user/notice")
@Api(tags = "APP公告",value = "APP公告API")
public class AppNoticeController {
    private static final Logger logger= LoggerFactory.getLogger(AppNoticeController.class);

    @Resource
    private NoticeService noticeService;
    //1.最新公告查询
    @GetMapping("/findNewNotice/{shopNo}")
    @ApiOperation(value = "获取某个店铺的最新公告", notes = "获取某个店铺的最新公告")
    public Result<NoticeResultDto> findNewNotice(@PathVariable("shopNo")String shopNo){
        try{
           return noticeService.findNewNotice(shopNo);
        }catch (Exception e){
            logger.error("查询最新公告发生异常:{}",e);
            return Result.newError(ResultCode.FAIL);
        }
    }

    //2.公告详情
    @GetMapping("findNoticeById/{noticeId}")
    public Result<NoticeResultDto> findNoticeById(@PathVariable("noticeId")String noticeId){
        try{
            if(!StringUtils.isNumeric(noticeId)){
                return Result.newError(ResultCode.COMMON_PARAM_INVALID);
            }
            return noticeService.findNoticeById(noticeId);
        }catch (Exception e){
            logger.error("公告详情发生异常:{}",e);
            return Result.newError(ResultCode.FAIL);
        }
    }

}
